package com.qingcloud.fexecutor.base.enums;

/**
 * 表索引类型枚举
 *
 * @author wangjinnan
 */
public enum TableIndexTypeEnum {

    /**
     * 主键索引
     */
    PRIMARY(1,"主键索引", "PRIMARY KEY"),

    /**
     * 唯一索引
     */
    UNIQUE(2, "唯一索引","UNIQUE KEY"),

    /**
     * 普通索引
     */
    NORMAL(3, "普通索引","KEY");

    /**
     * 类型编码
     */
    public final Integer code;

    public final String value;

    public final String sql;

    TableIndexTypeEnum(int code, String value,String sql) {
        this.code = code;
        this.value = value;
        this.sql = sql;
    }

    public static TableIndexTypeEnum getEnumByCode(Integer code) {
        TableIndexTypeEnum[] uss = values();
        for (TableIndexTypeEnum us : uss) {
            if (us.code.equals(code)) {
                return us;
            }
        }
        return null;
    }

    public static String valueOfCode(Integer code) {
        TableIndexTypeEnum[] uss = values();
        for (TableIndexTypeEnum us : uss) {
            if (us.code.equals(code)) {
                return us.value;
            }
        }
        return "";
    }

    public static Integer codeOfValue(String value) {
        TableIndexTypeEnum[] uss = values();
        for (TableIndexTypeEnum us : uss) {
            if (us.value.equals(value)) {
                return us.code;
            }
        }
        return TableIndexTypeEnum.NORMAL.code;
    }

    public String getSql() {
        return sql;
    }
}
